// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-11-11

package common

type (
    // SpanId
    // 链路跨度标识.
    SpanId interface {
        Byte() []byte
        String() string
    }

    spanId struct {
        bt  []byte
        str string
    }
)

// NewSpanId
// 创建随机链路跨度标识.
func NewSpanId() SpanId {
    o := &spanId{bt: singletonGenerator.Make(8)}
    o.str = singletonGenerator.Convert(o.bt)
    return o
}

// NewSpanIdWithHex
// 基于指定值创建链路跨度标识.
func NewSpanIdWithHex(s string) SpanId {
    o := &spanId{str: s}
    o.bt = singletonGenerator.Decode(s)
    return o
}

// Byte
// 取字节列表.
func (o *spanId) Byte() []byte {
    return o.bt
}

// String
// 取字符串.
func (o *spanId) String() string {
    return o.str
}
